<?php
// 配置类型模型
class ContentModel extends Model {
	
	
	//获得所有通过审核的内容(分页)
	
	public function getContentPageByCat($catId,$pageSize,$len=22){
		
			import("ORG.Util.Page"); // 导入分页类 
		  $count = $this->field('id')->where('cat='.$catId.' and status=1')->count();
		  $Page  = new Page($count,$pageSize);
		  $temp['page'] =  $Page->show();
		  $temp['list'] =  $this->field('id,title,style,cat,ctime,uname,info,status,model,img,isimg,istop,isrecom')->where('cat='.$catId.' and status=1')->order('ctime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		  foreach($temp['list'] as $key=>$v){
		  	$title = titleCut($len,$temp['list'][$key]['title']);
				if(!empty($v['style'])){
					 $strarr = explode(";",$v['style']);
	    		 if(is_array($strarr) && count($strarr)>=4){
	    		 	  
	    		 		if($strarr[3]){
	    		 			 $title =  '<font color="'.$strarr[3].'">'.$title.'</font>';
	    		 		}
	    		 		if($strarr[0]){
	    		 			$title =  '<strong>'.$title.'</strong>';
	    		 		}
	    		 		if($strarr[1]){
	    		 			$title =  '<i>'.$title.'</i>';
	    		 		}
	    		 		if($strarr[2]){
	    		 			$title =  '<s>'.$title.'</s>';
	    		 		}
	    		 	  
	    		 }
	    		 $strarr=null;
				}
				$temp['list'][$key]['title'] = $title;
			}
		  $temp['cat'] = D('Cat','admin')->getCatById($catId);
		  return $temp;
	}
	
	public function getContentList($cat=0,$istop=0,$isrecom=0,$num=10,$len=20){
		
		if($cat){
			 $map['cat'] = $cat;
		}else{
			$map['cat']  = array('neq',19);
		}
		if($istop){
			 $map['istop']=1;
		}
		if($isrecom){
			 $map['isrecom']=1;
		}
		
		$map['status'] = 1;
		
		$list = $this->field('id,title,style,cat,ctime,uname,info,status,model,img,isimg,istop,isrecom')->where($map)->order('ctime desc')->limit($num)->select();
		foreach($list as $key=>$v){
			  $title = titleCut($len,$list[$key]['title']);
				if(!empty($v['style'])){
					 $strarr = explode(";",$v['style']);
	    		 if(is_array($strarr) && count($strarr)>=4){
	    		 		if($strarr[3]){
	    		 			 $title =  '<font color="'.$strarr[3].'">'.$title.'</font>';
	    		 		}
	    		 		if($strarr[0]){
	    		 			$title =  '<strong>'.$title.'</strong>';
	    		 		}
	    		 		if($strarr[1]){
	    		 			$title =  '<i>'.$title.'</i>';
	    		 		}
	    		 		if($strarr[2]){
	    		 			$title =  '<s>'.$title.'</s>';
	    		 		}
	    		 	  
	    		 }
	    		 $strarr=null;
				}
				$list[$key]['title'] = $title;
			} 
		return $list;
	}
	
	public function getContentByPart($part=0,$istop=0,$isrecom=0,$num=10,$len=20){
		$cat = 0;
		if($part){
			$cats = D('Cat','admin')->getCatByMulu($part);
			if($cats){
				$cat = $cats['id'];
			}
		}
		$list = $this->getContentList($cat,$istop,$isrecom,$num,$len);
		return $list;
	}
	
	public function getPart($id){
		  $pcat = D('Cat','admin')->getCatPcat($id);
			$part = '';
			foreach($pcat as $p){
				$part .= ' > <a href="__APP__'.$p['listthtml'].'/partId/'.$p['id'].'" />'.$p['cname'].'</a>';
			}
			return $part;
	}
	
	public function getContent($cid){
		
		// 获取基本内容
		
		$content = M('Content')->where('id='.$cid.' and status=1')->find();
		$temp = array();
		if($content){
			
			$cat = D('Cat','admin')->getCatById($content['cat']);
			$ncontent = M($content['model'])->find($content['id']);
			if($ncontent){
				$content = array_merge($content,$ncontent);
			}
			$temp['content'] = $content;
			$temp['cat'] = $cat;
			
			return $temp;
			
		}else{
			return false;
		}
		
	}
	
	public function getSpage($partId){
		
		$spage = M('Spage')->where('cat='.$partId.' and status=1')->find();
		$cat = D('Cat','admin')->getCatById($partId);
		$temp['content'] = $spage;
		$temp['cat'] = $cat;
		return $temp;
	}
	
	
}
?>